clear; clc; close all;

%% 固定参数
a0 = -2;            % 论文中常用 a0
a1 = 0.83;          % 论文中常用 a1
b0 = 1.3;
b1 = 0.1;
b2 = 1;
d1 = 0;
d2 = 0;

% 迭代设置
N_total = 5000;   % 总迭代步数，可根据需求修改
N_trans = 100;    % 舍弃瞬态步数
N_show  = N_total - N_trans;

% 初始条件
x0 = 0.1;
y0 = 0.1;
z0 = 0.1;

a2_values = [-0.2, -0.18, -0.16, -0.14, -0.12, -0.1];

colors = lines(length(a2_values));  % 给不同的 a2 分配不同颜色

%% 绘图
figure;

subplot(1,2,1);
hold on; grid on; box on;
xlabel('x_n','FontSize',12);
ylabel('y_n','FontSize',12);
title(' a_2 变化偏移图', 'FontSize',14);

subplot(1,2,2);
hold on; grid on; box on;
xlabel('y_n','FontSize',12);
ylabel('z_n','FontSize',12);
title('a_2 旋转收缩图','FontSize',14);

for i = 1:length(a2_values)
    current_a2 = a2_values(i);
    col = colors(i,:);
    
    % 分配存储
    X = zeros(1, N_show);
    Y = zeros(1, N_show);
    Z = zeros(1, N_show);

    % 赋初值
    x = x0; 
    y = y0; 
    z = z0;
    
    % 先丢弃瞬态
    for n = 1:N_trans
        [x, y, z] = vl_dmsin(a0, a1, current_a2, b0, b1, b2, d1, d2, x, y, z);
    end
    
    % 记录后期轨迹
    for n = 1:N_show
        [x, y, z] = vl_dmsin(a0, a1, current_a2, b0, b1, b2, d1, d2, x, y, z);
        X(n) = x;
        Y(n) = y;
        Z(n) = z;
    end
    
    % 在左子图绘制 (x,y) 散点，用不同颜色
    subplot(1,2,1);
    scatter(X, Y, 5, 'MarkerFaceColor', col, 'MarkerEdgeColor','none',...
        'DisplayName', sprintf('a2=%.2f', current_a2));
    
    % 在右子图绘制 (y,z) 散点，用相同颜色
    subplot(1,2,2);
    scatter(Y, Z, 5, 'MarkerFaceColor', col, 'MarkerEdgeColor','none',...
        'DisplayName', sprintf('a2=%.2f', current_a2));
end

legend('Location','best');


